package cn.kilo.trigger.http.manage;

import cn.kilo.domain.model.order.entity.MUserEntity;
import cn.kilo.domain.model.order.res.MUserRes;
import cn.kilo.domain.service.infterface.IOrderStrategyService;
import cn.kilo.trigger.api.IManageService;
import cn.kilo.trigger.http.manage.Dto.MUserDTO;
import cn.kilo.types.enums.ResponseCode;
import cn.kilo.types.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author kilok
 */
@RestController
@RequestMapping("/manage")
@CrossOrigin("*")
@Slf4j
public class ManageController implements IManageService {

    @Resource
    private IOrderStrategyService orderService;

    /**
     * 获取总收入
     * @return
     */
    @GetMapping("/getAllIncome")
    @Override
    public Response<?> getAllSalary() {

        try {
            Long res = orderService.getAllSalary();
            return Response.<Long>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(res)
                    .build();
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("总收入获取失败")
                    .build();
        }
    }

    /**
     * 获取本月收入
     * @return
     */
    @GetMapping("/getMonthIncome")
    @Override
    public Response<?> getMonthSalary() {
        try {
            Long res = orderService.getMonthSalary();
            return Response.<Long>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(res)
                    .build();
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("总收入获取失败")
                    .build();
        }
    }

    /**
     * 获取用户总数
     * @return
     */
    @GetMapping("/getUserNumber")
    public Response<?> getUserNumber() {
        try {
            Integer ans=orderService.getUserNumber();
            return Response.<Integer>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(ans)
                    .build();
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("用户总人数获取失败")
                    .build();
        }
    }

    /**
     * 获取本月新增人数
     * @return
     */
    @GetMapping("/getMothUser")
    public Response<?> getMothUser() {
        try {
            Integer ans=orderService.getMothUser();
            return Response.<Integer>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(ans)
                    .build();
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("本月新增用户获取失败")
                    .build();
        }
    }

    /**
     * 获取总利润
     * @return
     */
    @GetMapping("/getAllMoney")
    public Response<?> getAllMoney() {
        try {
            Long ans=orderService.getAllMoney();
            return Response.<Long>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(ans)
                    .build();
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("总利润获取失败")
                    .build();
        }
    }

    /**
     * 获取本月利润
     * @return
     */
    @GetMapping("/getMothMoney")
    public Response<?> getMothMoney() {
        try {
            Long ans=orderService.getMothMoney();
            return Response.<Long>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(ans)
                    .build();
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("本月利润获取失败")
                    .build();
        }
    }

    /**
     * 获取总成本
     * @return
     */
    @GetMapping("/getAllOutcome")
    public Response<?> getAllOutcome() {
        try {
            Long ans=orderService.getAllOutcome();
            return Response.<Long>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(ans)
                    .build();

        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("总成本获取失败")
                    .build();
        }
    }

    /**
     * 获取总成本
     * @return
     */
    @GetMapping("/getMothOutcome")
    public Response<?> getMothOutcome() {
        try {
            Long ans=orderService.getMothOutcome();
            return Response.<Long>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .data(ans)
                    .build();

        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("本月成本获取失败")
                    .build();
        }
    }


    @GetMapping("/")
    public Response<?> test() {
        try {
            return null;
        } catch (Exception e) {
            return Response.<String>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .data("")
                    .build();
        }
    }
}
